using UwinEducation.Shared.Enums;
using UwinEducation.Application.Common.Helpers;

namespace UwinEducation.Application.Extensions
{
    /// <summary>
    /// 年级枚举扩展方法
    /// </summary>
    public static class GradeExtensions
    {
        /// <summary>
        /// 获取年级显示名称
        /// </summary>
        public static string GetDisplayName(this GradeEnum grade)
        {
            return grade switch
            {
                GradeEnum.Grade1 => "一年级",
                GradeEnum.Grade2 => "二年级",
                GradeEnum.Grade3 => "三年级",
                GradeEnum.Grade4 => "四年级",
                GradeEnum.Grade5 => "五年级",
                GradeEnum.Grade6 => "六年级",
                GradeEnum.Grade7 => "七年级",
                GradeEnum.Grade8 => "八年级",
                GradeEnum.Grade9 => "九年级",
                GradeEnum.Grade10 => "十年级",
                GradeEnum.Grade11 => "十一年级",
                GradeEnum.Grade12 => "十二年级",
                GradeEnum.Grade13 => "已毕业",
                _ => string.Empty
            };
        }
        /// <summary>
        /// 获取年级入学时间
        /// </summary>
        public static int GetEnrollmentDate(this GradeEnum grade)
        {
            return grade switch
            {
                GradeEnum.Grade1 => DateTime.Now.Year,
                GradeEnum.Grade2 => DateTime.Now.Year - 1,
                GradeEnum.Grade3 => DateTime.Now.Year - 2,
                GradeEnum.Grade4 => DateTime.Now.Year - 3,
                GradeEnum.Grade5 => DateTime.Now.Year - 4,
                GradeEnum.Grade6 => DateTime.Now.Year - 5,
                GradeEnum.Grade7 => DateTime.Now.Year - 6,
                GradeEnum.Grade8 => DateTime.Now.Year - 7,
                GradeEnum.Grade9 => DateTime.Now.Year - 8,
                GradeEnum.Grade10 => DateTime.Now.Year - 9,
                GradeEnum.Grade11 => DateTime.Now.Year - 10,
                GradeEnum.Grade12 => DateTime.Now.Year - 11,
                GradeEnum.Grade13 => DateTime.Now.Year - 12,
                GradeEnum.Grade14 => 1949,
                _ => 0
            };
        }
        public static GradeEnum GetGradeByEnrollmentDate(this GradeEnum grade, int enrollmentDate, int _year = 10, int _month = 1)
        {
            // 使用ServiceLocator获取配置值
            //int _year = ServiceLocator.GetConfigIntValue("grade11Month", 10); // 默认10月
            //int _month = ServiceLocator.GetConfigIntValue("grade11Data", 1);  // 默认1日

            //int _year = 10; // 默认10月
            //int _month =1;  // 默认1日

            int year = DateTime.Now.Year - enrollmentDate;
            if (enrollmentDate == 1949)
                year = -1;
                
            DateTime date = new DateTime(DateTime.Now.Year, _year, _month);
            return year switch
            {
                0 => GradeEnum.Grade1,
                1 => GradeEnum.Grade2,
                2 => GradeEnum.Grade3,
                3 => GradeEnum.Grade4,
                4 => GradeEnum.Grade5,
                5 => GradeEnum.Grade6,
                6 => GradeEnum.Grade7,
                7 => GradeEnum.Grade8,
                8 => GradeEnum.Grade9,
                9 => GradeEnum.Grade10,
                10 => DateTime.Now >= date ? GradeEnum.Grade12 : GradeEnum.Grade11,
                11 => GradeEnum.Grade12,
                -1 => GradeEnum.Grade14,
                _ => GradeEnum.Grade13
            };
        }
    }
}